//package com.example.good.config;
//
//import com.example.good.entity.User;
//import com.example.good.service.UserService;
//import org.apache.shiro.authc.AuthenticationException;
//import org.apache.shiro.authc.AuthenticationInfo;
//import org.apache.shiro.authc.AuthenticationToken;
//import org.apache.shiro.authc.SimpleAuthenticationInfo;
//import org.apache.shiro.authz.AuthorizationInfo;
//import org.apache.shiro.authz.SimpleAuthorizationInfo;
//import org.apache.shiro.realm.AuthorizingRealm;
//import org.apache.shiro.subject.PrincipalCollection;
//
//import javax.annotation.Resource;
//import java.util.HashSet;
//
//public class CustomRealm extends AuthorizingRealm {
//
//    @Resource
//    private UserService userService;
//
//    @Override
//    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
//
//        //获取名字
//        String name = (String) principalCollection.getPrimaryPrincipal();
//
//        SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
//        info.setStringPermissions(new HashSet<>(userService.getPermission(name)));
//        
//        return info;
//    }
//
//    @Override
//    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
//        String userName = (String) authenticationToken.getPrincipal();
//        User user = userService.login(userName);
//        if (user != null){
//            return new SimpleAuthenticationInfo(userName, user.getPassword(), this.getName());
//        }
//        return null;
//    }
//}